Subscribe Us

Responsive Advertisement

Advertisement

1549B Gregor and the Pawn Game codeforces solution in cpp

 1549B Gregor and the Pawn Game codeforces solution in cpp

by ujjal roy




#include<bits/stdc++.h>

using namespace std;

main()

{

    int t,n,i,c;

    cin>>t;

    while(t--)

    {

        cin>>n;

        string s,s1;

        cin>>s>>s1;

        c=0;

        for(i=0;i<n;i++)

        {

            if(s1[i]=='1')

            {

                if(s[i]=='0') c++;

                else

                {

                    if(i==0)

                    {

                        if(s[i+1]=='1')

                        {

                            c++;

                            s[i+1]='0';

                        }

                    }

                    else

                    {

                        if(s[i-1]=='1')

                        {

                            s[i-1]='0';

                            c++;

                        }

                        else if(s[i+1]=='1')

                        {

                            s[i+1]='0';

                            c++;

                        }

                    }

                }

            }

        }

        cout<<c<<endl;

    }



    return 0;

}


Post a Comment

0 Comments